package com.example.interactactivity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    private EditText editHello;
    private Button butSend;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editHello = (EditText)findViewById(R.id.editHello);
        butSend = (Button)findViewById(R.id.btSend);

        butSend.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                Bundle bundle = new Bundle();
                bundle.putInt("num",1);
                bundle.putString("msg",editHello.getText().toString());

                Intent intent = new Intent(MainActivity.this,SecondActivity.class);
                intent.putExtras(bundle);
                startActivityForResult(intent,1);
            }
        });
    }
    @Override
    protected void onActivityResult(int requertCode,int resultCode,Intent data){
        super.onActivityResult(requertCode,resultCode,data);

        if(requertCode==1){
            Bundle retBundle = data.getExtras();
            String retMsg = retBundle.getString("msg");

            editHello.setText("");
            editHello.setHint("收到回复" + retMsg);
        }
    }
}
